package collection;

import java.util.HashMap;
import java.util.Map;

/**
 * Map接口常用方法
 */
@SuppressWarnings("all")
public class MapMethod {

    public static void main(String[] args) {


        //put 添加
        Map map = new HashMap();
        map.put("邓超",new marry("",100));//OK
        map.put("邓超", "孙俪");//替换
        map.put("王宝强", "马蓉");//OK
        map.put("宋喆", "马蓉");//OK

        System.out.println("map=" + map);

        //remove 根据键删除映射关系
        map.remove(null);
        System.out.println("map=" + map);

        //get 根据键获取值
        Object val = map.get("邓超");
        System.out.println("val=" + val);

        //size 获取元素个数
        System.out.println("k-v=" + map.size());

        //isEmpty 判断个数是否为0
        System.out.println(map.isEmpty());//F

        //clear 清除 k-v
        //map.clear();
        System.out.println("map=" + map);

        //containsKey 查找键是否存在
        System.out.println("结果=" + map.containsKey("lmy"));//T
    }
}

class marry{

    private String name;

    private int num;

    public marry(String name, int num) {
        this.name = name;
        this.num = num;
    }
}